<template>
	<el-dialog title="添加老师" visible :show-close="false" class="wrap" size="tiny">
        <i class="el-icon-close close" @click="cancel"></i>
        <el-form label-width="100px" class="form">
            <el-form-item label="老师中文名">
                <el-input v-model="form.chinese" class="select-block"></el-input>
            </el-form-item>
            <el-form-item label="老师英文名">
                <el-input v-model="form.english" class="select-block"></el-input>
            </el-form-item>
            <el-form-item label="老师类型">
                <el-select v-model="form.type" placeholder="请选择..." class="select-block">
                	<el-option label="老师" value="ls"></el-option>
                	<el-option label="助教" value="zj"></el-option>
                	<el-option label="助教" value="xz"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="电话">
                <el-input v-model="form.phone" class="select-block"></el-input>
            </el-form-item>
            <el-form-item label="性别">
                <el-switch v-model="form.sex" on-color="#13ce66" off-color="#ff4949" on-value="男" off-value="女" on-text="男" off-text="女"></el-switch>
            </el-form-item>
            <el-form-item label="学校">
                <el-select v-model="form.school" placeholder="请选择..." class="select-block">
                	<el-option :label="v.mc" :value="v.id" v-for="v in schoolList"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="注册时间">
                <!-- <el-input v-model="form.time"></el-input> -->
                <el-date-picker v-model="form.time" type="date" placeholder="选择日期" class="select-block" @change="getTime"></el-date-picker>
            </el-form-item>
            <el-form-item label="是否启用">
                <el-switch v-model="form.isqy" on-value="Y" off-value="N"></el-switch>
            </el-form-item>
        </el-form>
        <el-button type="info" class="submit" @click="submit">添加</el-button>
    </el-dialog>
</template>

<script type="text/javascript">
	export default {
		data () {
			return {
				form: {
					type: '',
					isqy: 'Y',
					school: '',
					chinese: '',
					english: '',
					phone: '',
					sex: '男',
					time: ''
				},
				type: '',
				schoolList: []
			}
		},
		created () {
			this.getSchoolList();
		},
		methods: {
			submit () {
                this.$store.state.loading = true;
				if (!this.form.chinese) {
					this.$message.warning('请填写老师中文名');
					return;
				}else if(!this.form.type){
					this.$message.warning('请选择老师类型');
					return;
				}else if(!this.form.school){
					this.$message.warning('请选择学校');
					return;
				}else if(!this.form.time){
					this.$message.warning('请选择注册时间');
					return;
				}
                this.axios.get( this.$store.state.api + 'emp/add', {
                    params: {
                        zwm: this.form.chinese,
                        ywm: this.form.english,
                        dh: this.form.phone,
                        xb: this.form.sex,
                        xxid: this.form.school,
                        zcsj: this.form.time,
                        isqy: this.form.isqy,
                        emptype: this.form.type,
                    }
                }).then( res => {
                	// console.log({
                 //        zwm: this.form.chinese,
                 //        ywm: this.form.english,
                 //        dh: this.form.phone,
                 //        xb: this.form.sex,
                 //        xxid: this.form.school,
                 //        zcsj: this.form.time,
                 //        isqy: this.form.isqy,
                 //        emptype: this.form.type,
                 //    })
                 //    console.log(res)
                    if (res.data.code == 1) {
                    	this.$emit('close',{type:'add',cancel:false});
                        this.$store.state.loading = false;
                    }else{
                    	this.$emit('close',{type:'add',cancel:false});
                    	this.$store.state.loading = false;
                    }
                    
                }).catch( res => {
                    console.log(res)
                	this.$emit('close',{type:'add',cancel:false});
                	this.$store.state.loading = false;
                })
            },
            getTime (val) {
            	this.form.time = val;
            },
            cancel () {
                this.$emit('close',{type:'add',cancel:true})
            },
            getSchoolList () {
                this.axios.get( this.$store.state.api + 'emp/xxlist')
                .then( res => {
                    console.log(res)
                    this.schoolList = res.data.data.list;
                }).catch( res => {
                    console.log(res)
                })
            }
		}
	}
</script>

<style lang="less" scoped>
    .wrap {
        text-align: center;
    }
    .form {
        // width: 300px;
        text-align: left;
    }
    .select-block {
        display: block;
    }
    .submit {
        width: 120px;
    }
</style>